package dto.app;

import models.application.*;
import models.pubobj.*;
import models.user.*;
import utils.AniGeneralUtils;

import java.util.*;

public class UploadAppInfoDto extends AppInfoDto {

    public Long id;

    public String appName;

    public String description;

    public String forwardUrl;

    public Long classificationId;

    public Long typeId;

    public Long relyOnAppId;

    public AniUser ownerUser;

    public static String[] requiredRegisterFieldKeys = {
            "appName",
            "classificationId",
            "typeId",
    };
    public static String[] requiredUpdateFieldKeys = {
            "id"
    };

    public UploadAppInfoDto(Long appId, AniUser oneUser){
        this.id = appId;
        this.ownerUser = oneUser;
    }

    public UploadAppInfoDto(Map<String, String> appInfoMap, AniUser oneUser){
        this.id = AniGeneralUtils.translateStrId(appInfoMap.get("id"));
        this.appName = appInfoMap.get("appName").trim();
        this.description = appInfoMap.get("description").trim();
        this.classificationId = AniGeneralUtils.translateStrId(appInfoMap.get("classificationId"));
        this.typeId = AniGeneralUtils.translateStrId(appInfoMap.get("typeId"));
        this.relyOnAppId = AniGeneralUtils.translateStrId(appInfoMap.get("relyOnAppId"));
        this.forwardUrl = appInfoMap.get("forwardUrl");
        this.ownerUser = oneUser;
    }

    public AniApp getAniAppDao(AniObjectState oneState, String token){
        return new AniApp(
                this.id,
                this.ownerUser,
                this.relyOnAppId,
                this.classificationId,
                token,
                this.typeId,
                oneState,
                this.appName,
                this.description,
                this.forwardUrl
        );
    }
    public AniApp getAniAppDao(AniObjectState oneState){
        return new AniApp(
                this.id,
                this.ownerUser,
                this.relyOnAppId,
                this.classificationId,
                null,
                this.typeId,
                oneState,
                this.appName,
                this.description,
                this.forwardUrl
        );
    }
    public AniApp getAniAppDao(){
        return new AniApp(
                this.id,
                this.ownerUser,
                this.relyOnAppId,
                this.classificationId,
                null,
                this.typeId,
                null,
                this.appName,
                this.description,
                this.forwardUrl
        );
    }
}
